package Lee_code;

import java.text.DateFormatSymbols;

/**
 * @author blh
 * @date 2024年07月02日 14:53
 */
public class Lee_695_72 {
    int maxArea = 0;
    int m, n;
    int tempArea = 0;
    public int maxAreaOfIsland(int[][] grid) {
        m = grid.length;
        n = grid[0].length;
        int maxArea = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                islandDfs(i, j, grid);
                maxArea = Math.max(maxArea, tempArea);
                tempArea = 0;
            }
        }


        return maxArea;
    }

    private void islandDfs(int i, int j, int[][] grid) {

        if (i < 0 || i >= m || j < 0 || j >= n || grid[i][j] == 0) {
            return;
        }
        tempArea++;
        grid[i][j]=0;
        islandDfs(i-1, j, grid);
        islandDfs(i+1, j, grid);
        islandDfs(i, j+1, grid);
        islandDfs(i, j-1, grid);
    }
}
